package dk.itu.mobile.client;

import dk.itu.smds.e2012.week04.RestClient;

public class RESTClient extends RestClient implements Clientable{
	
	public static final String URI = "http://trustcare.itu.dk/task-manager-rest/tasks/";

	public String GetAttendantTasks(String AttendantId) {
		String response = "";
		String uri = URI + "attendant/" + AttendantId;
		
		response = DoRestCall(uri, "GET", "");
		
		return response;
	}

	public String CreateTask(String taskXml) {
		String response = "";
		String uri = URI + "createtask";
		
		response = DoRestCall(uri, "POST", taskXml);
		
		return response;
	}

	public String DeleteTask(String taskId) {
		String response = "";
		String uri = URI + "DeleteTask?taskId=" + taskId;
		
		response = DoRestCall(uri, "DELETE", taskId);		
		
		return response;
	}
    
    public static void main(String[] args) {
    	Clientable testClient = new RESTClient();
    	String testAttendant = "rao";
    	String testAttendant2 = "dianaross";
    	String testTaskXML = "<task id='club54' name='The End of Modern-day Gomorrah' date='04-02-1980' status='so-executed'><description>Closing party of Club 54</description><attendants>andywarhole, michaeljackson, dianaross, rao</attendants></task></tasks>";
    	String testTaskId = "club54";
    	
    	//Test get GetAttendantTasks method
    	String attendantsTasks =  testClient.GetAttendantTasks(testAttendant);
    	//Attendants task as xml
    	System.out.println(testAttendant + "'s  tasks: \n" + attendantsTasks);
    	System.out.println();
    	
    	//Test CreateTask method
    	String createTaskResult = testClient.CreateTask(testTaskXML);
    	System.out.println("createTaskResult: " + createTaskResult);
    	System.out.println();
    	
    	//Test on testAttendant2
    	attendantsTasks =  testClient.GetAttendantTasks(testAttendant2);
     	//Attendants task as xml
    	System.out.println(testAttendant2 + "'s  tasks: \n" + attendantsTasks);
    	System.out.println();
    	System.out.println();
    	
    	//Test CreateTask method
    	createTaskResult = testClient.CreateTask(testTaskXML);
    	System.out.println("createTaskResult: " + createTaskResult);
    	System.out.println();
    	
    	//Test on testAttendant2
    	attendantsTasks =  testClient.GetAttendantTasks(testAttendant2);
     	//Attendants task as xml
    	System.out.println(testAttendant2 + "'s  tasks: \n" + attendantsTasks);
    	System.out.println();
    	
    	//Test DeleteTask method
    	String deleteTaskResult = testClient.DeleteTask(testTaskId);
    	System.out.println("deleteTaskResult: " + deleteTaskResult);
    	System.out.println();
    	
    	//Test get GetAttendantTasks method to verify test calls to CreateTask and DeleteTask
    	attendantsTasks =  testClient.GetAttendantTasks(testAttendant);
     	//Attendants task as xml
    	System.out.println(testAttendant + "'s  tasks: \n" + attendantsTasks);
    	System.out.println();
    	
    	//Test on testAttendant2
    	attendantsTasks =  testClient.GetAttendantTasks(testAttendant2);
     	//Attendants task as xml
    	System.out.println(testAttendant2 + "'s  tasks: \n" + attendantsTasks);
    	System.out.println();
    	
    	
    }
}
